package com.example.service;

import com.example.entity.ArticleCategory;
import com.example.entity.NullArticleCategory;
//import com.example.config.RedisCacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

@Component
public class ArticleCategoryService {
    private static final String CACHE_KEY_ARTICLE_CATEGORY = "article_category";

    static {
        //RedisCacheConfig.setCacheTime(CACHE_KEY_ARTICLE_CATEGORY, 60L * 30);
    }

    @Cacheable(value = CACHE_KEY_ARTICLE_CATEGORY)
    public ArticleCategory findById(Long categoryId) {

        if (categoryId == null) {
            return new NullArticleCategory();
        }

        ArticleCategory category = new ArticleCategory();
        category.setCategoryId(new Random().nextLong());
        category.setCategoryCode("0001");
        category.setCategoryName("新闻");
        category.setParentCode("0");
        category.setLastUpdateTime(new Date());

        return category;
    }
}
